import { toSuccess, useTransaction } from "@sker/core"
import { SysMenu } from "@sker/entities"
import { Like } from "typeorm"

export default async () => {
    await useTransaction(async m => {
        // 检查是否有s3菜单
        const menus = await m.find(SysMenu, { where: { name: Like('ImeeposMiniprogram%') } })
        const addonMenus: any[] = [
            { name: 'ImeeposMiniprogram', title: '小程序管理', url: null, main: null, is_group: true },
            { name: 'ImeeposMiniprogramWebAccount', title: '小程序账号', pname: 'ImeeposMiniprogram', url: '/imeepos/miniprogram/web/account', main: '/@imeepos/miniprogram/public/web/account.js', is_group: false },
        ]
        const toSave = addonMenus.map(menu => {
            const item = menus.find(it => it.name === menu.name)
            if (item) {
                menu.id = item.id;
            }
            return menu;
        })
        await m.save(SysMenu, toSave)
    })
    return toSuccess(true)
}